package base;

/**
 * Element contains informations that have to be analyse. Created in
 * {@link Source} they end their way in the process of a {@link Server}.
 * 
 * @author rweiller
 * 
 */
public class Element
{
	public int	base_weight;
	public int	weight;
	public int	time_load_balancer;
	public int	time_server;
	public int	id_server;
	public int	input;
	public int	output;

	public Element(int weight)
	{
		setBaseWeight(weight);
		setTimeLoadBalancer(0);
		setTimeServer(0);
	}

	public int getBaseWeight()
	{
		return base_weight;
	}

	public int getIdServer()
	{
		return id_server;
	}

	public int getInput()
	{
		return input;
	}

	public int getOutput()
	{
		return output;
	}

	public int getTimeLoadBalancer()
	{
		return time_load_balancer;
	}

	public int getTimeServer()
	{
		return this.time_server;
	}

	public int getWeight()
	{
		return weight;
	}

	/**
	 * Set base weight of the Element and his weight.
	 * 
	 * @param base_weight the base weight of the element.
	 * @throws IllegalArgumentException if the base_weight is minor to 1.
	 */
	public void setBaseWeight(int base_weight) throws IllegalArgumentException
	{
		if (base_weight < 1)
		{
			throw new IllegalArgumentException("Weight must be > 0");
		}
		this.base_weight = base_weight;
		this.weight = base_weight;
	}

	/**
	 * Set id_server from where the element was sent.
	 * 
	 * @param id_server the server id.
	 */
	public void setIdServer(int id_server)
	{
		this.id_server = id_server;
	}

	/**
	 * Set output number, means the index when the Element was extract from the
	 * source.
	 * 
	 * @param input the index number.
	 * @throws IllegalArgumentException if output is minor to 0.
	 */
	public void setInput(int input) throws IllegalArgumentException
	{
		if (input < 0)
		{
			throw new IllegalArgumentException("Input must be positive");
		}
		this.input = input;
	}

	public void setOutput(int output)
	{
		if (output < 0)
		{
			throw new IllegalArgumentException("Output must be positive");
		}
		this.output = output;
	}

	/**
	 * Set time spent in the Loadbalancer.
	 * 
	 * @param time the time spent.
	 * @throws IllegalArgumentException if time is minor to 0.
	 */
	public void setTimeLoadBalancer(int time) throws IllegalArgumentException
	{
		if (time < 0)
		{
			throw new IllegalArgumentException("Time load balancer must be > 0");
		}
		this.time_load_balancer = time;

	}

	/**
	 * Set time spent in the Server.
	 * 
	 * @param time the time spent.
	 * @throws IllegalArgumentException if time is minor to 0.
	 */
	public void setTimeServer(int time) throws IllegalArgumentException
	{
		if (time < 0)
		{
			throw new IllegalArgumentException("Time server must be positive");
		}
		this.time_server = time;
	}

	/**
	 * Set weight of the Element.
	 * 
	 * @param weight the weight.
	 * @throws IllegalArgumentException if weight is minor to 0.
	 */
	public void setWeight(int weight) throws IllegalArgumentException
	{

		if (weight < 0)
		{
			throw new IllegalArgumentException("Weight must be positive");
		}
		this.weight = weight;
	}
}
